﻿#ifndef MAINWINDOWSIGNALHANDLER_H
#define MAINWINDOWSIGNALHANDLER_H

#include <QObject>
#include <QString.h>
#include <QDomNodeList>
#include <QDomElement>
#include <QDomDocument>
#include <QDomAttr>
#include "PostEnumType.h"
#include "DialogDataImportConfiguration.h"

#define MainWindowSignalHandlerInstance pst::MainWindowSignalHandler::getInstance()
namespace pst
{
    class CenterWidget;
    class MainWindow;
    class TextFileParser;
    class LineChartWindow;
    class InfomationGraph3DBasical;
    class MainWindowSignalHandler : public QObject
    {
        Q_OBJECT
    private:
        MainWindowSignalHandler() = default;
        ~MainWindowSignalHandler() = default;

    public:
        // 获取单例
        static MainWindowSignalHandler* getInstance();

        void setCenterWidget(CenterWidget* centerWidget) { m_centerWidget = centerWidget; };
        CenterWidget* getCenterWidget() const { return m_centerWidget; }

        void setMainWindow(MainWindow* mainWindow) { m_mainWindow = mainWindow; };
        MainWindow* getMainWindow() const { return m_mainWindow; }

        void setActiveGeometryState(bool state) { m_isActiveGeometry = state; }

        void setToolButtonExportMotionGraphState(bool state);

        bool getIsDynamicTypeCamera();
        void setIsDynamicTypeCamera(bool isCamera);

        CurrentWindowType getCurrentGraphWindowType();

        TextFileParser* getTextFileParserByProjectTreeItem(int projectTreeItemID);
        TextFileParser* getTextFileParserByDataSourceByOpenProject(QString dataSources);

        InfomationGraph3DBasical* BuildCompleteGraph3DInfoByProjectTreeItem(int projectTreeItemID, GraphType graphType); // 构造完整的3Dinformation

        /// 从工程文件读入数据
        void readDataFromProjectFile(QDomNodeList* nodeList);

        bool TextImportDataProcessing(int itemID, QString filePath, const QVector<std::tuple<QString, DialogDataImportConfiguration::DataProperty, QVector<double>>>& datas, QVector<QPair<QPointF, int>> resultFileData, FileDataTypes fileDataType);

    private:
        static MainWindowSignalHandler* m_instance;

    public slots:

        // 主页
        void slot_toolButtonOpenProjectFile();
        void slot_toolButtonProjectResultSave();
        void slot_toolButtonDataImport(QString lastSelectPath);
        void slot_toolButtonFormatViewClicked();
        void slot_comboBoxStandardSelectionCurrentIndexChanged(int index);
        void slot_comboBoxDataSelectionCurrentIndexChanged(int index);
        void slot_toolButtonAIQAClicked();

        // 数据分析
        void slot_toolButtonTotalQuantityCalculation(); // 总量计算
        void slot_toolButtonHirfExtrapolationClicked();
        void slot_toolButtonIPLCalculationClicked();
        void slot_toolButtonWaveformAnalysisClicked();
        void slot_toolButtonLightningZoningClicked();
        void slot_toolButtonShieldingEfficiencyClicked();
        void slot_toolButtonTransferFunctionClicked();
        void slot_toolButtonFFTClicked();
        void slot_toolButtonBasicAnalysisClicked();
        void slot_toolButtonCorrelationAnalysisClicked();
        void slot_toolButtonCumulativeDistributionFunctionClicked();
        void slot_toolButtonCurveSmoothingClicked();
        void slot_toolButtonLinearInterpolationClicked();                 // 线性插值
        void slot_toolButtonLogarithmicInterpolationSingleAxisXClicked(); // 单X轴对数插值
        void slot_toolButtonLogarithmicInterpolationSingleAxisYClicked(); // 单Y轴对数插值
        void slot_toolButtonLogarithmicInterpolationDoubleAxisClicked();  // 双对数轴对数插值
        void slot_toolButtonSplineInterpolationClicked();                 // 样条插值
        void slot_toolButtonPolynomialInterpolationClicked();             // 多项式插值
        void slot_toolButtonThunderstormZoneClicked();
        // void slot_measureButtonClicked();
        void slot_measureButtonClicked(MeasureType type, double value = 0);
        void slot_toolButtonEvaluationSubmission();
        // 显示
        void slot_toolButtonSelfAdaptationClicked();
        void slot_toolButtonAmplifyClicked();
        void slot_toolButtonMinificationClicked();
        void slot_toolButtonTranslationClicked(bool checked);
        void slot_toolButtonRotationClicked(bool checked);
        void slot_toolButtonIsometricViewClicked();
        void slot_toolButtonTopViewClicked();
        void slot_toolButtonUpwardViewClicked();
        void slot_toolButtonFrontViewClicked();
        void slot_toolButtonRearViewClicked();
        void slot_toolButtonLeftViewClicked();
        void slot_toolButtonRightViewClicked();
        void slot_updateClipperAndGeometry(bool isActiveClipper, bool isActiveGeometry, bool& hasAnyGeometrySuccess);
        void py_updateClipperAndGeometry(int windowUniversalID, bool isActiveClipper, bool isActiveGeometry, bool& hasAnyGeometrySuccess);
        void py_activeClipperSettingData(int windowUniversalID, bool toolButtonActiveClipperIsChecked, bool toolButtonModelDisplayIsChecked, bool hasAnyGeometrySuccess, QString direction, double clipperValue);
        void slot_comboBoxNormalCurrentIndexChanged(int index);
        void slot_clipperOriginValueChanged(double value);
        void slot_toolButtonFastBackClicked();
        void slot_toolButtonPlayClicked(bool checked);
        void slot_toolButtonFastForwardClicked();
        void slot_toolButtonDynamicTypeClicked();
        void slot_toolButtonDynamicTypeCameraClicked();
        void slot_toolButtonDynamicTypeDataClicked();
        void slot_toolButtonDynamicSettingClicked(bool isActionCameraEnable, bool isActionDataEnable);
        void slot_toolButtonExportMotionGraphClicked();
        void slot_toolButtonShieldingEfficiencyClickedFormCommad(const QString& graphNames, double e0);

        bool slot_computeHIRF(const QString& graphNames, double incidentWaveFieldValue,
            const QString& HIRFName, const QString& typeName, bool isCheckBoxChecked);

        void slot_submitEvaluationGlobal(int emulationType, const QStringList& graphNameList);

    private:
        void updateAnimationSpeedBottonState(double speed);
        QStringList getInitParams(const LineChartWindow* lineChartWindow);
        bool isEdit();

    private:
        void printErrorMessage();
        CenterWidget* m_centerWidget{nullptr};
        bool m_translationChosen{false};
        bool m_rotationChosen{false};
        MainWindow* m_mainWindow{nullptr};
        bool m_toolButtonPlayState{false};
        bool m_isActiveClipper{false};
        bool m_isActiveGeometry{false};
        bool m_isDynamicTypeCamera{true}; // 类型相机为相机动图（true）或数据动图（false）
    };
} // namespace pst
#endif
